import React, {useEffect, useState} from "react";
import {Button, Checkbox, Input, Modal, Pagination, Select, Space, Table, Tag, notification, Popconfirm, Upload, Spin, Radio } from "antd";
// import {PlusOutlined} from '@ant-design/icons';
// import { Swiper, SwiperSlide } from 'swiper/react';
import 'swiper/swiper.scss';
import http from "../../../../request";
import {BASE_URL, UPLOAD_URL} from "../../../../request/api";
import {store} from "../../../../store";

const { Option } = Select;
const Tab2 = (props) => {
    const {id,house} = props
    const postFormDefault = {
        estate_id: id,
        name: '',
        num_type: '123',
        num: '',
        company: undefined,
        unit: '',
        total_layers: '',
        is_elevator: 0,
        elevator_num: undefined,
        household_num: undefined,
        store_id: undefined,
        staff_id: undefined,
    }
    const [pageInfo, setPageInfo] = useState({
        page: 1,
        pageSize: 10
    }) // 分页
    const [total, setTotal] = useState(0) // 列表总数
    const [source, setSource] = useState([]) // 列表
    const [columns] = useState([
        {
            title: '序号',
            dataIndex: 'id',
            key: 'id',
            // sorter: (a, b) => a.id - b.id,
        }, {
            title: '栋座名',
            key: 'name',
            render: text => (text.name.length<2?0+text.name:text.name) + '栋' + text.num + '单元' ,
            sorter: (a, b) => ((a.name.length<2?0+a.name:a.name) + '栋' + a.num + '单元').localeCompare(((b.name.length<2?0+b.name:b.name) + '栋' + b.num + '单元')),
        }, {
            title: '总层',
            dataIndex: 'total_layers',
            key: 'total_layers',
        }, {
            title: '梯户',
            key: 'elevator_num',
            render: text => ((text?.elevator_num??'') +'-' + (text?.household_num??''))
        }, {
            title: '单元',
            dataIndex: 'unit',
            key: 'unit',
        },
        // {
        //     title: '房号',
        //     dataIndex: 'room_num',
        //     key: 'room_num',
        // },
         {
            title: '电梯',
            dataIndex: 'is_elevator',
            key: 'is_elevator',
            render: text => text === 1 ? <Tag color="red">有</Tag> : <Tag color="warning">无</Tag>
        }, {
            title: '部门',
            dataIndex: 'store_data',
            key: 'store_id',
            render: text => text?.name?text.name: ''
        }, {
            title: '负责人',
            dataIndex: 'staff_data',
            key: 'staff_id',
            render: text => text?.nickname??''
        }, {
            title: '操作',
            key: 'action',
            render: text => (
                <Space size="middle">
                    <img className="u-btn" src={require('../../../../assets/icon/icon-12.png').default} alt="" title="编辑" onClick={() => postEdit(text.id)}/>
                    <Popconfirm title="确定删除？" okText="确定" cancelText="取消" onConfirm={() => postDel(text.id)}>
                        <img className="u-btn" src={require('../../../../assets/icon/icon-13.png').default} alt="" title="删除"/>
                    </Popconfirm>
                </Space>
            ),
        }
    ]) // 表-列

    const [block, setBlock] = useState({
        show: !1,
        text: ''
    }) // 新增-编辑-栋座-modal
    const [postForm, setPostForm] = useState(postFormDefault) // 新增-编辑-栋座-初始值

    const [storeList, setStoreList] = useState([]) // 部门列表
    const [userList, setUserList] = useState([]) // 员工列表

    const [del, setdel] = useState(!1)

    const [batch, setBatch] = useState({
        show: !1,
        text: ''
    })  // 批量-新增-栋座
    const [batchRang, setBatchRang] = useState(['', ''])
    const [batchSource, setBatchSource] = useState([]) // 批量-新增-表格数据
    const [batchColumns] = useState([
        {
            title: '栋座名',
            key: 'name',
            render: text => text.name + '-' + text.num,
        }, {
            title: '总层数',
            dataIndex: 'total_layers',
            key: 'total_layers'
        }, {
            title: '梯户数',
            key: 'elevator_num',
            render: text => ((text?.elevator_num?text.elevator_num+'梯':'') + (text?.household_num?text.household_num+'户':''))
        }, {
            title: '单元',
            dataIndex: 'unit',
            key: 'unit',
        }, {
            title: '电梯',
            dataIndex: 'is_elevator',
            key: 'is_elevator',
            render: text => text === 1 ? <Tag color="red">有</Tag> : <Tag color="warning">无</Tag>
        }
    ]) // 批量-新增-表格-列

    const [trans, setTrans] = useState({
        show: !1
    }) // 房源更换
    const [transArr, setTransArr] = useState([undefined, undefined])
    const [buildAll, setBuildAll] = useState([])
    const [file, setFile] = useState({
        show: !1
    })
    const [mask, setMask] = useState({show: !1, text: '上传中...'})
    const [selectList, setSelectList] = useState([])
    const [fileDefault, setFileDefault] = useState([])
    const [fileList, setFileList] = useState([])
    const [preview, setPreview] = useState({show: !1, content: ''})
    const [upload, setUpload] = useState({show: !1})
    const rowSelection = {
        selectedRowKeys: selectList,
        onChange: (key) => {
            setSelectList(key)
        }
    }
    const uploadConfig = {
        name: "file",
        accept: 'image/*, video/*',
        fileList: fileList,
        listType: 'picture',
        // showUploadList: false,
        multiple: true,
        action: UPLOAD_URL,
        headers: {
            token: store.getState().userInfo.token
        },
        beforeUpload: res => {
            if(!fileType(res.type)){
                notification.error({
                    message: '请上传图片/视频'
                })
            }
        },
        onChange: ({fileList}) => {
            setFileList(fileList)
        },
        onPreview: {filePreview}
    }

    const [fiex,setfiex] = useState(!1)

    const [ys,setys] = useState(0)

    useEffect(() => {
        listGet()
        storeGet()
        // eslint-disable-next-line react-hooks/exhaustive-deps
    }, [pageInfo])

    useEffect(()=>{
        console.log(batchRang);
    },[batchRang])

    return (
        <React.Fragment>
            <div className="part-title">栋座列表</div>
            <div className="u-m-t-20 u-flex-top">
                <div style={{flex:1}}>
                    <Table bordered rowSelection={rowSelection} rowKey={e => e.id} onRow={e => ({
                        onDoubleClick: () => {
                            postEdit(e.id)
                        }
                    })} size={'small'} dataSource={source} columns={columns} pagination={false} />
                </div>
                <div className="" style={{width:140}}>
                    <div >
                        <Button  size="small" className="u-flex u-m-l-20 " style={{width:120,}} onClick={reset}>
                            <img src={require('../../../../assets/icon/icon-7.png').default} alt=""/>
                            <span className="u-m-l-5">刷新栋座</span>
                        </Button>
                        <Button type="primary" size="small" className="u-flex u-m-l-20 u-m-t-10" style={{width:120,}} onClick={() => modalShow(setBlock, '添加')}>
                            <img src={require('../../../../assets/icon/icon-9.png').default} alt=""/>
                            <span className="u-m-l-5">新增栋座</span>
                        </Button>
                        {/* <Button  size="small" className="u-flex u-m-l-20 u-m-t-10" style={{width:120,}} >
                            <img src={require('../../../../assets/icon/icon-7.png').default} alt=""/>
                            <span className="u-m-l-5">加入[单栋]</span>
                        </Button> */}
                        <Button type="primary" size="small" className="u-flex u-m-l-20 u-m-t-10" style={{width:120}} onClick={() => modalShow(setBatch, '【百花】')}>
                            <img src={require('../../../../assets/icon/icon-25.png').default} alt=""/>
                            <span className="u-m-l-5">批量生成栋座</span>
                        </Button>
                        <Button type="primary" size="small" className="u-flex u-m-l-20 u-m-t-10" style={{width:120}} >
                            <img src={require('../../../../assets/icon/icon-25.png').default} alt=""/>
                            <span className="u-m-l-5">修改栋座</span>
                        </Button>
                        <Button type="primary" size="small" danger className="u-flex u-m-l-20 u-m-t-10" style={{width:120}} onClick={()=>setdel(!0)}>
                            <img src={require('../../../../assets/icon/icon-10.png').default} alt=""/>
                            <span className="u-m-l-5">删除栋座</span>
                        </Button>
                        <Button size="small" className="u-flex u-m-l-20 u-m-t-10" style={{background: '#2c9ef7', color: '#ffffff',width:120}} onClick={transShow}>
                            <img src={require('../../../../assets/icon/icon-26.png').default} alt=""/>
                            <span className="u-m-l-5">房源更改栋座</span>
                        </Button>
                        {/* <Button size="small" className="u-flex u-m-l-20" style={{background: '#2c9ef7', color: '#ffffff'}} onClick={fileShow}>
                            <img src={require('../../../../assets/icon/icon-27.png').default} alt=""/>
                            <span className="u-m-l-5">图片管理</span>
                        </Button> */}
                    </div>
                </div>
            </div>
            <div className="u-flex u-row-right u-m-t-20">
                <Pagination showQuickJumper current={pageInfo.page} pageSize={pageInfo.pageSize} total={total} onChange={(page, pageSize) => setPageInfo({page, pageSize})} />
            </div>
            <Modal title={block.text+"栋座"} okText="保存" width={600} visible={block.show} onOk={postSave} onCancel={() => modalHide(setBlock)}>
                <div className="Modal">
                    <div className="u-flex">
                        <div className="label ">栋座名称</div>
                        <Input placeholder="栋" value={postForm.name} onChange={e => postChange('name', e.target.value)} className="u-m-l-10" style={{width: 300}} />
                        <Input placeholder="单元" value={postForm.num} onChange={e => postChange('num', e.target.value)}  style={{width: 150}} />
                        
                    </div>
                    <div className="u-flex u-m-t-20">
                        <div className="label u-m-l-14">总层数</div>
                        <Input placeholder="总层数" value={postForm.total_layers} onChange={e => postChange('total_layers', e.target.value)} className="u-m-l-10" style={{width: 150}} />
                        <div className="label u-m-l-10">层</div>
                        <div className="u-m-l-40">电梯</div>
                        <Checkbox checked={postForm.is_elevator === 1} onChange={e => postChange('is_elevator', e.target.checked?1:0)} className="u-m-l-5" />
                        
                    </div>
                    <div className="u-flex u-m-t-20">
                        <div className="label u-m-l-14">梯户数</div>
                        <Select placeholder="电梯数" value={postForm.elevator_num} onChange={e => postChange('elevator_num', e)} className="u-m-l-10" style={{width: 150}}>
                            {
                                new Array(20).fill(1).map((e, i) => <Option value={i + 1} key={'elevator-'+i}>{i + 1}</Option>)
                            }
                        </Select>
                        <div className="label u-m-l-10">梯</div>
                        <Select placeholder="户数" value={postForm.household_num} onChange={e => postChange('household_num', e)} className="u-m-l-40" style={{width: 100}}>
                            {
                                (new Array(20)).fill(1).map((e, i) => <Option value={i + 1} key={'household-'+i}>{i + 1}</Option>)
                            }
                        </Select>
                        <div className="label u-m-l-10">户</div>
                    </div>
                    <div className="u-flex u-m-t-20">
                        <div className="label u-m-l-14">单元数</div>
                        <Select placeholder="单位" value={postForm.company} onChange={e => postChange('company', e)} className="u-m-l-10" style={{width: 150}}>
                            <Option value="数字">数字</Option>
                        </Select>
                        <div className="label u-m-l-10">有</div>
                        {/*<div className="label u-m-l-20">单元数</div>*/}
                        <Input placeholder="单元" value={postForm.unit} onChange={e => postChange('unit', e.target.value)} className="u-m-l-40" style={{width: 100}} />
                        <div className="label u-m-l-10">单元</div>
                    </div>
                    <div className="u-flex u-m-t-20">
                        <div className="label u-m-l-14">责任人</div>
                        <Select placeholder="部门" value={postForm.store_id} onChange={storeChange} className="u-m-l-10" style={{width: 300}}>
                            {
                                storeList.map(store => <Option value={store.id} key={store.id}>{store.name}</Option>)
                            }
                        </Select>
                        <Select placeholder="员工" value={postForm.staff_id} onChange={e => postChange('staff_id', e)}  style={{width: 150}}>
                            {
                                userList.map(user => <Option value={user.id} key={user.id}>{user.nickname}</Option>)
                            }
                        </Select>
                    </div>
                </div>
            </Modal>
            <Modal title="房源更改栋座" okText="保存" width={410} visible={trans.show} onOk={transConfirm} onCancel={() => modalHide(setTrans)}>
                <div className="u-flex">
                    <div>楼盘字典</div>
                    <Input disabled  value={house} style={{width:213}} className="u-m-l-10 u-m-r-10"></Input>
                    <div>的所有房源:</div>
                </div>
                <div className="u-flex u-m-t-5">
                    <div className="label">原栋座为</div>
                    <Select placeholder="原栋座" value={transArr[0]} onChange={e => transChange(0, e)} className="u-m-l-10" style={{width: 120}}>
                        {
                            buildAll.map(build => <Option value={build.id} key={build.id}>{build.name}-{build.num}{build.company}</Option>)
                        }
                    </Select>
                    <div className="label u-m-l-10">改为</div>
                    <Select placeholder="新栋座" value={transArr[1]} onChange={e => transChange(1, e)} className="u-m-l-10" style={{width: 120}}>
                        {
                            buildAll.map(build => <Option value={build.id} key={build.id}>{build.name}-{build.num}{build.company}</Option>)
                        }
                    </Select>
                </div>
            </Modal>
            <Modal title={`批量生成栋座`} width={700} footer={false} visible={batch.show} onCancel={() => modalHide(setBatch)}>
                <div className="Modal">
                    <div className="u-flex">
                        <div className="label u-m-l-100">前缀</div>
                        <Checkbox checked={fiex} onChange={e=>setfiex(e.target.checked)} className="u-m-l-100">栋数两位(01.02)</Checkbox>
                        <div className="label u-m-l-70">后缀</div>
                    </div>
                    <div className="u-flex">
                        <div className="label">栋座名称</div>
                        <Input placeholder="栋座名称" value={postForm.name} onChange={e => postChange('name', e.target.value)} className="u-m-l-10" style={{width: 120}} />
                        <div className="u-flex-top">
                            <div className="u-m-l-10">
                                <Radio.Group value={ys} onChange={e=>changeys(e.target.value)}>
                                    <Radio value={0}></Radio><br/>
                                    <Radio value={1} className="u-m-t-10"></Radio>
                                </Radio.Group>
                            </div>
                            <div>
                            <div className="u-flex">
                                <Input placeholder="1" value={batchRang[0]} onChange={e => batchRangChange(0, e.target.value)} style={{width: 80,height:25}} disabled={ys=== 0 ? false : true}/>
                                <div className="label u-m-l-10">至</div>
                                <Input placeholder="10" value={batchRang[1]} onChange={e => batchRangChange(1, e.target.value)} className="u-m-l-10" style={{width: 80,height:25}} disabled={ys=== 0 ? false : true}/>
                            </div>
                            <div className="u-flex u-m-t-5">
                                <Input placeholder="A" value={batchRang[0]} onChange={e => batchRangChange(0, e.target.value)} style={{width: 80,height:25}} disabled={ys=== 1 ? false : true}/>
                                <div className="label u-m-l-10">至</div>
                                <Input placeholder="H" value={batchRang[1]} onChange={e => batchRangChange(1, e.target.value)} className="u-m-l-10" style={{width: 80,height:25}} disabled={ys=== 1 ? false : true}/>
                            </div>
                            </div>
                        </div>
                        <Select placeholder="单位"  className="u-m-l-10" style={{width: 100}}>
                            <Option value="单元">单元</Option>
                        </Select>
                    </div>
                    <div className="u-flex u-m-t-20">
                        <div className="label u-m-l-14">总层数</div>
                        <Input placeholder="单元数" value={postForm.total_layers} onChange={e => postChange('total_layers', e.target.value)} className="u-m-l-10" style={{width: 150}} />
                        <div className="label u-m-l-5">层</div>
                        <div className="u-m-l-40">电梯</div>
                        <Checkbox checked={postForm.is_elevator === 1} onChange={e => postChange('is_elevator', e.target.checked?1:0)}  className="u-m-l-5"/>
                        
                    </div>
                    <div className="u-flex u-m-t-20">
                        <div className="label u-m-l-14">楼户数</div>
                            <Select placeholder="电梯数" value={postForm.elevator_num} onChange={e => postChange('elevator_num', e)} className="u-m-l-10" style={{width: 150}}>
                                {
                                    new Array(20).fill(1).map((e, i) => <Option value={i + 1} key={'elevator-'+i}>{i + 1}</Option>)
                                }
                            </Select>
                            <div className="label u-m-l-5">梯</div>
                            <Select placeholder="户数" value={postForm.household_num} onChange={e => postChange('household_num', e)} className="u-m-l-40" style={{width: 120}}>
                                {
                                    (new Array(20)).fill(1).map((e, i) => <Option value={i + 1} key={'household-'+i}>{i + 1}</Option>)
                                }
                            </Select>
                        <div className="label u-m-l-10">户</div>
                    </div>
                    <div className="u-flex u-row-between ">
                        <div className="u-flex">
                            <div className="label u-m-l-14">单元数</div>
                            <Select placeholder="单位" value={postForm.company} onChange={e => postChange('company', e)} className="u-m-l-10" style={{width: 150}}>
                                <Option value="数字">数字</Option>
                            </Select>
                            <div className="label u-m-l-5">有</div>
                            <Input placeholder="单元数" value={postForm.unit} onChange={e => postChange('unit', e.target.value)} className="u-m-l-40" style={{width: 120}} />
                            <div className="label u-m-l-10">单元</div>
                        </div>
                        
                        <div className="u-m-r-60">
                            <Button type="primary" size="small" ghost onClick={() => batchSave(1)} className="u-m-l-20">预览</Button><br/>
                            <Button type="primary" size="small" ghost onClick={() => batchSave(0)} className="u-m-l-20 u-m-t-5">生成</Button><br/>
                            <Button type="primary" size="small" ghost onClick={() => modalHide(setBatch)} className="u-m-l-20 u-m-t-5">取消</Button>
                        </div>
                    </div>
                    <div>
                    <div className="u-flex">
                        <div className="label ">所属部门</div>
                            <Select placeholder="部门" value={postForm.store_id} onChange={storeChange} className="u-m-l-10" style={{width: 150}}>
                                {
                                    storeList.map(store => <Option value={store.id} key={store.id}>{store.name}</Option>)
                                }
                            </Select>
                            <Select placeholder="员工" value={postForm.staff_id} onChange={e => postChange('staff_id', e)} className="u-m-l-58" style={{width: 120}}>
                                {
                                    userList.map(user => <Option value={user.id} key={user.id}>{user.nickname}</Option>)
                                }
                            </Select>
                        </div>
                    </div>
                    <div className="u-m-t-20">
                        <Table bordered size="small" scroll={{y: 400}} rowKey={e => e.id} dataSource={batchSource} columns={batchColumns} pagination={false} />
                    </div>
                    <div className="u-m-t-20 tip">即将生成{batchSource.length}个栋座</div>
                </div>
            </Modal>
            <Modal title="图片管理" visible={file.show} width={750} onOk={() => modalHide(setFile)} onCancel={() => modalHide(setFile)}>
                <div className="Modal Building-Edit">
                    <div className="u-flex u-flex-wrap" style={{maxHeight: '500px', overflowY: 'auto'}}>
                        {
                            fileDefault.map(file => (
                                <div className="file-item" key={file.id}>
                                    { file.type === 'image' && <img className="u-btn file" src={BASE_URL + file.content} alt="" onClick={() => filePreview(file)}/>}
                                    { file.type === 'video' && <video className="file" src={BASE_URL + file.content} controls style={{background: '#000'}} /> }
                                    <Button type="primary" size="small" className="u-flex file-del" onClick={() => fileDel(file.id)}>
                                        <img src={require('../../../../assets/icon/icon-10.png').default} alt=""/>
                                        <span className="u-m-l-5">删除</span>
                                    </Button>
                                </div>
                            ))
                        }
                    </div>

                    <div className="u-flex u-m-t-20">
                        <Button type="primary" size="small" className="u-flex" onClick={() => modalShow(setUpload)}>
                            <img src={require('../../../../assets/icon/icon-9.png').default} alt=""/>
                            <span className="u-m-l-5">上传图片</span>
                        </Button>
                        <Button type="primary" size="small" className="u-flex u-m-l-20" onClick={() => fileDel()}>
                            <img src={require('../../../../assets/icon/icon-10.png').default} alt=""/>
                            <span className="u-m-l-5">全部删除</span>
                        </Button>
                    </div>
                </div>
            </Modal>
            <Modal visible={upload.show} maskClosable={false} width={880} onOk={fileConfirm} onCancel={fileCancel}>
                <div className="Modal Building-Edit">
                    { mask.show && (
                        <div className="mask">
                            <Spin size="large" tip={mask.text} />
                        </div>
                    ) }
                    <Upload {...uploadConfig} className="upload-list-inline">
                        <Button type="primary" size="small" className="u-flex">
                            <img src={require('../../../../assets/icon/icon-9.png').default} alt=""/>
                            <span className="u-m-l-5">选择图片</span>
                        </Button>
                    </Upload>
                </div>
            </Modal>
            <Modal visible={preview.show} width={1000} footer={null} onCancel={() => {setPreview({show: !1})}}>
                {preview.type === 'image' && <img src={preview.content} alt="" style={{width: '100%'}}/>}
                {preview.type === 'video' && <video src={preview.content} controls style={{width: '100%', maxHeight: '80vh', background: '#000'}}/>}
            </Modal>
            <Modal title="提示信息" visible={del} onCancel={()=>setdel(!1)} onOk={()=>{
                postDel()
                setdel(!1)
            }}>
                <p>警告：删除[栋座]将删除其关联[房号]记录!</p>
                <p>确定要永久删除选定的栋座吗？</p>
            </Modal>
        </React.Fragment>
    )

    function listGet(){
        http('building.index', {
            filter: JSON.stringify({estate_id: id}),
            op: JSON.stringify({estate_id: '='}),
            offset: (pageInfo.page - 1) * pageInfo.pageSize,
            limit: pageInfo.pageSize
        }).then(res => {
            if(res.code === 1){
                setSource(res.data.rows)
                setTotal(res.data.total)
            }
        })
    }
    function storeGet(){
        http('store.list').then(res => {
            if(res.code === 1){
                setStoreList(res.data.rows)
            }
        })
    }
    function storeChange(e){
        postChange('store_id', e)
        http('user.list', {
            store_id: e
        }).then(res => {
            if(res.code === 1){
                setUserList(res.data)
            }
        })
    }
    function postChange(name = '', value = null){
        let newPostForm = JSON.parse(JSON.stringify(postForm))
        newPostForm[name] = value
        setPostForm(newPostForm)
    }
    function postSave(){
        let url = postForm?.id ? 'building.edit' : 'building.add'
        http(url, {
            row: postForm
        }).then(res => {
            if(res.code === 1){
                notification.success({
                    message: '提醒',
                    description: res.msg || '操作成功',
                    duration: 2,
                })
                modalHide(setBlock)
                setPostForm(postFormDefault)
                listGet()
            } else {
                notification.error({
                    message: '错误',
                    description: res.msg || '操作失败，请重试',
                    duration: 2,
                })
            }
        })
    }
    function postEdit(ids){
        http('building.one', {ids}).then(res => {
            if(res.code === 1){
                setPostForm(res.data)
                modalShow(setBlock, '修改')
                if(res.data.staff_id > 0){
                    http('user.list', {
                        store_id: res.data.store_id
                    }).then(e => {
                        if(e.code === 1){
                            setUserList(e.data)
                        }
                    })
                }
            }
        })
    }
    function postDel(id){
        let ids = id > 0 ? [id] : selectList
        http('building.del', {ids}).then(res => {
            if(res.code === 1){
                listGet()
            }
        })
    }
    function reset(){
        // render()
        console.log(1);
        listGet()
    }

    function batchRangChange(ind, value){
        let newRang = JSON.parse(JSON.stringify(batchRang))
        newRang[ind] = value
        setBatchRang(newRang)
    }
    function batchSave(is_view){
        console.log({
            is_view,
            estate_id: id,
            name: postForm.name,
            num_type: postForm.num_type,
            num: batchRang.join('-'),
            company: postForm.company,
            unit: postForm.unit,
            total_layers: postForm.total_layers,
            is_elevator: postForm.is_elevator,
            elevator_num: postForm.elevator_num,
            household_num: postForm.household_num,
            store_id: postForm.store_id,
            staff_id: postForm.staff_id,
        });
        http('building.batch', {
            is_view,
            estate_id: id,
            name: postForm.name,
            num_type: postForm.num_type,
            num: batchRang.join('-'),
            company: postForm.company,
            unit: postForm.unit,
            total_layers: postForm.total_layers,
            is_elevator: postForm.is_elevator,
            elevator_num: postForm.elevator_num,
            household_num: postForm.household_num,
            store_id: postForm.store_id,
            staff_id: postForm.staff_id,
        }).then(res => {
            if(res.code === 1){
                if(is_view === 1){
                    console.log(res);
                    // 预览
                    setBatchSource(res.data)
                } else {
                    notification.success({
                        title: '提示',
                        message: res.msg || '操作成功',
                    })
                    modalHide(setBatch)
                    listGet()
                }
            } else {
                notification.error({
                    title: '错误',
                    message: res.msg || '操作失败，请重试'
                })
            }
        })
    }
    
    function transShow(){
        http('building.index', {
            filter: JSON.stringify({estate_id: id}),
            op: JSON.stringify({estate_id: '='})
        }).then(res => {
            if(res.code === 1){
                setBuildAll(res.data.rows)
            }
        })
        modalShow(setTrans)
    }
    function transChange(name, value = null){
        let newTransArr = JSON.parse(JSON.stringify(transArr))
        newTransArr[name] = value
        setTransArr(newTransArr)
    }
    function transConfirm(){
        http('building.move', {
            old_id: transArr[0],
            new_id: transArr[1]
        }).then(res => {
            if(res.code === 1){
                notification.success({
                    title: '提示',
                    message: res.msg || '操作成功',
                })
                modalHide(setTrans)
            } else {
                notification.error({
                    title: '错误',
                    message: res.msg || '操作失败，请重试'
                })
            }
        })
    }
    function fileShow(){
        http('estate.resource.index', {
            filter: JSON.stringify({estate_id: id}),
            op: JSON.stringify({estate_id: '='})
        }).then(res => {
            if(res.code === 1){
                setFileDefault(res.data.rows)
                modalShow(setFile)
            }
        })
    }
    function fileType(type){
        if(type.indexOf('image') === 0){
            return 'image'
        }
        if(type.indexOf('video') === 0){
            return 'video'
        }
        return false;
    }
    function fileConfirm(){
        let status = fileList.every(e => {
            return e.status === 'done'
        })
        if(status){
            setMask({show: !0, text: '提交中...'})
            http('estate.resource.add.batch', {
                row: fileList.map(file => {
                    return {
                        estate_id: id,
                        // name: file.name,
                        type: fileType(file.type),
                        content: file.content??file.response.data.url
                    }
                })
            }).then(res => {
                if(res.code === 1){
                    setMask({show: !0, text: '上传成功'})
                    fileShow()
                    setTimeout(() => {
                        setMask({show: !1})
                        setFileList([])
                        modalHide(setUpload)
                    }, 1000)
                } else {
                    setMask({show: !0, text: ''})
                    notification.error({
                        message: res.msg || '操作失败，请重试'
                    })
                }
            })
        } else {
            notification.error({
                message: '请等待图片上传完毕'
            })
        }
    }
    function fileCancel(){
        setFileList([])
        modalHide(setUpload)
    }
    function filePreview(file){
        setPreview({
            show: !0,
            type: fileType(file.type),
            content: BASE_URL + (file.content??file.response.data.url)
        })
    }
    function fileDel(ids){
        let url = 'estate.resource.del' + (ids > 0 ? '' : '.batch')
        let data = ids > 0 ? {ids} : {estate_id: id}
        http(url, data).then(res => {
            if(res.code === 1){
                fileShow()
            }
        })
    }
    function modalShow(func, text = ''){
        func({show: !0, text})
    }
    function modalHide(func){
        func({show: !1, text: ''})
    }

    function changeys(e){
        setys(e)
        setBatchRang([null,null])
    }
}

export default Tab2